"""
有一个数组arr
[[0,3], [1,2], [2,3]]
arr[i]中的两个元素是相同的关系
"""

arr = [[0, 3], [1, 2], [3, 1]]

res = [0, 1, 2, 3]


def find(x):
    if res[x] == x:
        return x
    else:
        res[x] = find(res[x])
        return res[x]


def merge(i, j):
    x = find(i)
    y = find(j)

    res[x] = y


for a in arr:
    merge(a[0], a[1])

for i in range(len(res)):
    find(i)

print(res)
